{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Working on a Windows 10\n", "Python version 3.11.8 | packaged by conda-forge | (main, Feb 16 2024, 20:40:50) [MSC v.1937 64 bit (AMD64)]\n", "Pandas version 2.2.3\n", "bifacial_radiance version 0.5.0b2.dev4+gedb973d.d20250924\n" ] } ], "source": [ "# This information helps with debugging and getting support :)\n", "import sys, platform\n", "import pandas as pd\n", "import bifacial_radiance as br\n", "print(\"Working on a \", platform.system(), platform.release())\n", "print(\"Python version \", sys.version)\n", "print(\"Pandas version \", pd.__version__)\n", "print(\"bifacial_radiance version \", br.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 22 - Mirrors and Modules\n", "\n", "\n", "Doing an example tutorial for example brought up in Issue #372\n", "\n", "![Mirror and Module Combo](../images_wiki/AdvancedJournals/22_mirror_moduleCombo.PNG)\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Your simulation will be stored in C:\\Users\\cdeline\\Documents\\Python Scripts\\Bifacial_Radiance\\bifacial_radiance\\TEMP\\Tutorial_22\n" ] } ], "source": [ "import os\n", "from pathlib import Path\n", "\n", "testfolder = str(Path().resolve().parent.parent / 'bifacial_radiance' / 'TEMP' / 'Tutorial_22')\n", "if not os.path.exists(testfolder):\n", " os.makedirs(testfolder)\n", " \n", "print (\"Your simulation will be stored in %s\" % testfolder)\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import bifacial_radiance\n", "import numpy as np\n", "import pprint \n", "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "path = C:\\Users\\cdeline\\Documents\\Python Scripts\\Bifacial_Radiance\\bifacial_radiance\\TEMP\\Tutorial_22\n", "Loading albedo, 1 value(s), 0.200 avg\n", "1 nonzero albedo values.\n", "Getting weather file: USA_VA_Richmond.724010_TMY2.epw\n", " ... OK!\n", "8760 line in WeatherFile. Assuming this is a standard hourly WeatherFile for the year for purposes of saving Gencumulativesky temporary weather files in EPW folder.\n", "Coercing year to 2021\n", "Saving file EPWs\\metdata_temp.csv, # points: 8760\n", "Calculating Sun position for Metdata that is right-labeled with a delta of -30 mins. i.e. 12 is 11:30 sunpos\n" ] }, { "data": { "text/plain": [ "'skies\\\\sky2_37.5_-77.33_2021-01-01_1200.rad'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "demo = bifacial_radiance.RadianceObj('tutorial_22', path=testfolder) # Adding a simulation name. This is optional.\n", "demo.setGround(0.2) \n", "epwfile = demo.getEPW(lat=37.5, lon=-77.6) \n", "metdata = demo.readWeatherFile(weatherFile=epwfile, coerce_year=2021) \n", "timeindex = metdata.datetime.index(pd.to_datetime('2021-01-01 12:0:0 -5'))\n", "demo.gendaylit(timeindex) # Choosing a december time when the sun is lower in the horizon\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Create your module and evaluate irradiance without the mirror element" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Module Name: test-module\n", "Module test-module updated in module.json\n", "Pre-existing .rad file objects\\test-module.rad will be overwritten\n", "\n" ] } ], "source": [ "tilt = 75\n", "sceneDict1 = {'tilt':tilt,'pitch':5,'clearance_height':0.05,'azimuth':180, \n", " 'nMods': 1, 'nRows': 1, 'originx': 0, 'originy': 0, 'appendRadfile':True} \n", "mymodule1 = demo.makeModule(name='test-module',x=2,y=1, numpanels=1)\n", "sceneObj1 = demo.makeScene(mymodule1, sceneDict1) " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Created tutorial_22.oct\n", "Linescan in process: tutorial_22_Row1_Module1_Front\n", "Linescan in process: tutorial_22_Row1_Module1_Back\n", "Saved: results\\irr_tutorial_22_Row1_Module1.csv\n" ] } ], "source": [ "octfile = demo.makeOct(demo.getfilelist()) \n", "analysis = bifacial_radiance.AnalysisObj(octfile, demo.basename)\n", "frontscan, backscan = analysis.moduleAnalysis(sceneObj1, sensorsy=1)\n", "results = analysis.analysis(octfile, demo.basename, frontscan, backscan) " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'C:\\\\Users\\\\cdeline\\\\Documents\\\\Python Scripts\\\\Bifacial_Radiance\\\\bifacial_radiance\\\\TEMP\\\\Tutorial_22'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pwd" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xyzrearZmattyperearMatWm2FrontWm2BackBack/FrontRatiorearXrearY
00.0-0.0240.540.532a0.0.a0.test-module.6457a0.0.a0.test-module.2310140.20364.9040.4630.00.005
\n", "
" ], "text/plain": [ " x y z rearZ mattype \\\n", "0 0.0 -0.024 0.54 0.532 a0.0.a0.test-module.6457 \n", "\n", " rearMat Wm2Front Wm2Back Back/FrontRatio rearX rearY \n", "0 a0.0.a0.test-module.2310 140.203 64.904 0.463 0.0 0.005 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "withoutMirror = bifacial_radiance.load.read1Result('results\\irr_tutorial_22_Row1_Module1.csv')\n", "withoutMirror" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Add Mirror\n", "\n", "### Approach 1: Pretend the mirror is another module.\n", "\n", "We start by creating the mirror material in our ground.rad file, in case it is not there. For mirror or glass primitives (material classes), pecularity and roughness are not needed. \n", "\n", "You could alternatively do a plastic material, and increase the specularity and lower the roughness to get a very reflective surface." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Material exists, overwriting...\n", "\n", "Added material testmirror to file ground.rad\n" ] } ], "source": [ "demo.addMaterial(material='testmirror', Rrefl=0.94, Grefl=0.96, Brefl=0.96, \n", " materialtype = 'mirror') # specularity and roughness not needed for mirrors or glass. " ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Module Name: test-mirror\n", "Module test-mirror updated in module.json\n", "Pre-existing .rad file objects\\test-mirror.rad will be overwritten\n", "\n" ] } ], "source": [ "mymodule2 = demo.makeModule(name='test-mirror',x=2,y=1, numpanels=1, modulematerial='testmirror')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We calculate the displacement of the morrir as per the equations show in the image at the beginning of the tutorial " ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "originy = -(0.5*mymodule2.sceney + 0.5*mymodule1.sceney*np.cos(np.radians(tilt)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make a second sceneObj and add to the octfile. `Append=True` required, otherwise the second scene will overwrite the first!" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Additional scene Scene1 created! See list of names with RadianceObj.scenes and sceneNames\n" ] } ], "source": [ "sceneDict2 = {'tilt':0,'pitch':0.00001,'clearance_height':0.05,'azimuth':180, \n", " 'nMods': 1, 'nRows': 1, 'originx': 0, 'originy': originy, 'appendRadfile':True} \n", "sceneObj2 = demo.makeScene(mymodule2, sceneDict2, append=True) " ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Created tutorial_22.oct\n" ] } ], "source": [ "octfile = demo.makeOct(demo.getfilelist()) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use rvu in the terminal or by commenting out the cell below to view the generated geometry, it should look like this:\n", " \n", "![Mirror and Module Combo](../images_wiki/AdvancedJournals/22_mirror_moduleCombo_rvu.PNG)\n", "\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "## Comment the line below to run rvu from the Jupyter notebook instead of your terminal.\n", "## Simulation will stop until you close the rvu window\n", "\n", "# !rvu -vf views\\front.vp -e .01 -vp 4 -0.6 1 -vd -0.9939 0.1104 0.0 tutorial_22.oct" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Linescan in process: tutorial_22_withMirror_Row1_Module1_Front\n", "Linescan in process: tutorial_22_withMirror_Row1_Module1_Back\n", "Saved: results\\irr_tutorial_22_withMirror_Row1_Module1.csv\n" ] } ], "source": [ "analysis = bifacial_radiance.AnalysisObj(octfile, demo.basename)\n", "frontscan, backscan = analysis.moduleAnalysis(sceneObj1, sensorsy=1)\n", "results = analysis.analysis(octfile, name=demo.basename+'_withMirror', frontscan=frontscan, backscan=backscan) " ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xyzrearZmattyperearMatWm2FrontWm2BackBack/FrontRatiorearXrearY
00.0-0.0240.540.532a0.0.a0.test-module.6457a0.0.a0.test-module.2310172.07964.7920.3770.00.005
\n", "
" ], "text/plain": [ " x y z rearZ mattype \\\n", "0 0.0 -0.024 0.54 0.532 a0.0.a0.test-module.6457 \n", "\n", " rearMat Wm2Front Wm2Back Back/FrontRatio rearX rearY \n", "0 a0.0.a0.test-module.2310 172.079 64.792 0.377 0.0 0.005 " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "withMirror = bifacial_radiance.load.read1Result('results\\irr_tutorial_22_withMirror_Row1_Module1.csv')\n", "withMirror" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Just as a sanity check, we could sample the mirror..." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Linescan in process: tutorial_22_Mirroritself_Row1_Module1_Front\n", "Linescan in process: tutorial_22_Mirroritself_Row1_Module1_Back\n", "Saved: results\\irr_tutorial_22_Mirroritself_Row1_Module1.csv\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xyzrearZmattyperearMatWm2FrontWm2BackBack/FrontRatiorearXrearY
00.0-0.6290.0750.045a0.0.a0.test-mirror.6457a0.0.a0.test-mirror.2310160.2640.3180.0020.0-0.629
\n", "
" ], "text/plain": [ " x y z rearZ mattype \\\n", "0 0.0 -0.629 0.075 0.045 a0.0.a0.test-mirror.6457 \n", "\n", " rearMat Wm2Front Wm2Back Back/FrontRatio rearX rearY \n", "0 a0.0.a0.test-mirror.2310 160.264 0.318 0.002 0.0 -0.629 " ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "frontscan, backscan = analysis.moduleAnalysis(sceneObj2, sensorsy=1)\n", "results = analysis.analysis(octfile, name=demo.basename+'_Mirroritself', frontscan=frontscan, backscan=backscan) \n", "bifacial_radiance.load.read1Result('results\\irr_tutorial_22_Mirroritself_Row1_Module1.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And we can calculate the increase in front irradiance from the mirror:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gain from mirror: 22.7 %\n" ] } ], "source": [ "print(\"Gain from mirror:\", round((withMirror.Wm2Front[0] - withoutMirror.Wm2Front[0] )*100/withoutMirror.Wm2Front[0],1 ), \"%\" )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Approach 2: \n", "\n", "Create mirrors as their own objects and Append to Scene, like on tutorial 5. Sample code below:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "# name='Mirror1'\n", "# text='! genbox black cuteMirror 2 1 0.02 | xform -t -1 -0.5 0 -t 0 {} 0'.format(originy)\n", "# customObject = demo.makeCustomObject(name,text)\n", "# demo.appendtoScene(radfile=scene.radfiles, customObject=customObject, text=\"!xform -rz 0\")\n", "# sceneObj2 = demo.makeScene(mymodule2, sceneDict2) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and then you do your Scene, Oct, and Analysis as usual." ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.8" } }, "nbformat": 4, "nbformat_minor": 4 }